package com.project.ryudo.SessionBean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.project.entity.Account;

import com.project.entity.Staff;

/**
 * Session Bean implementation class AccountBean
 */
@Stateless
@LocalBean
public class AccountBean implements AccountBeanRemote {

    /**
     * Default constructor. 
     */
	@PersistenceContext
	EntityManager em;
	
	public static final String RemoteJNDIName = AccountBean.class.getSimpleName() + "/remote";
    public static final String LocalJNDIName = AccountBean.class.getSimpleName() + "/local";
    
    public AccountBean() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public List LoginUserIn(String email, String password) {
		Query query = em.createQuery("select acc from Account acc where acc.email = :email and acc.password = :password");
		query.setParameter("email", email);
		query.setParameter("password", password);
		List result = query.getResultList();
		return result;
	}
	
	

	@Override
	public List CheckEmail(String email) {
		Query query = em.createQuery("select acc from Account acc where acc.email = :email");
		query.setParameter("email", email);
		List result = query.getResultList();
		return result;
	}

	@Override
	public void updateBasicInfo(Account acc) 
	{
		em.merge(acc);	
	}
	
	@Override
	public List loadAllUsers() {
		Query query = em.createNamedQuery("Account.findAllUsers");
		List result = query.getResultList();
		return result;
	}

	@Override
	public void addNewAccount(Account account) {
		em.persist(account);
		
	}

	@Override
	public List loadRequestedUser(String AccID) {
		Query query = em.createQuery("select acc from Account acc where acc.accID = :accID");
		query.setParameter("accID", Integer.parseInt(AccID));
		List result = query.getResultList();
		return result;
	}

	

	
	
	

}
